package utils

import (
	"bytes"
	"golang.org/x/text/encoding/simplifiedchinese"
	"golang.org/x/text/transform"
	"io"
)

func UTF82GBK(str []byte) ([]byte, error) {
	GB18030 := simplifiedchinese.All[0]
	b, err := io.ReadAll(transform.NewReader(bytes.NewReader(str), GB18030.NewEncoder()))
	return b, err
}

func GBK2UTF8(str []byte) (string, error) {
	GB18030 := simplifiedchinese.All[0]
	b, err := io.ReadAll(transform.NewReader(bytes.NewReader(str), GB18030.NewDecoder()))
	return string(b), err
}
